<!-- TrainGroupList.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
	<title>集团切换学习和实习frame</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" href="../../css/mui.min.css" />
	<link rel="stylesheet" href="../../css/base.css"/>
	<!--<link rel="stylesheet" href="../../css/CFNetPP_Base.css">-->
	<style type="text/css" media="screen">
	    body{
	    	background-color: white;
	    }
		.mui-table-view-radio .mui-table-view-cell .mui-navigate-right:after{
			color: #18b4ed;
		}
		.trainGroupTitle{
            width: 100%;
            height: 40px;
            line-height: 40px;
            text-align: center;
            font-size: 16px;
		}
		.sub-title{
			float: right;
		}
	</style>
</head>
<body>

    <div class="main" hidden="hidden">
        <li id="section1" class="mui-table-view trainGroupTitle"> 学习集团 </li>
    	<ul id="group_list" class="mui-table-view mui-table-view-radio">
    		
		</ul>
		<li id="section2" class="mui-table-view trainGroupTitle"> 实习集团 </li>
    	<ul id="group_list2" class="mui-table-view mui-table-view-radio">

		</ul>
	</div>
	<div class="noSign" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button"  onclick="loadNewData()" class="mui-btn mui-btn-outlined">
				重新加载
			</button>
		</div>
</body>
<script type="text/javascript" src="../../script/mui.min.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
    var stdydata = "";
    var index = "";
    var dataSource = [];
    var dataSource2 = [];
	apiready = function(){
		loaddata();
	}
	function loadNewData() {
		loaddata();
	}
	function loaddata() {
        showProgress();
        var url = url_getJiTuanList;
        var params = {
        	uid : $api.getStorage('cfnetppuid')
        }
        cfnetppPOST(url, params, true, function(data, status) {
            hideProgress();
            if (status == 'success') {
            	if (data.code == 200) {
	            	$('.main').show();
	                dataSource = data.data.jiaoxue;
	                $api.setStorage('stdydata', dataSource);
	                setupGroupData(dataSource);
	                // alert(JSON.stringify(dataSource));
	                dataSource2 = data.data.shixi;
	                $api.setStorage('practicedata', dataSource2);
	                setupGroupData2(dataSource2);
	                // alert(JSON.stringify(dataSource2));
            	} else if(data.code == 190){//只教学
	               	$('.main').show();
	                dataSource = data.data.jiaoxue;
	                $api.setStorage('stdydata', dataSource);
	                setupGroupData(dataSource);
             	} else if (data.code == 191){//只实习
					$('.main').show();
					dataSource2 = data.data.shixi;
					$api.setStorage('practicedata', dataSource2);
					setupGroupData2(dataSource2);
	            } else {
	                $('#noData').show();
	                $('.main').hide();
	                $('#noNet').hide();
	            }
            } else {
            	$('#noData').hide();
                $('.main').hide();
                $('#noNet').show();
            }
        });
    }
	function setupGroupData(groupDatas){
		var groupHtml = '';
		for (var i = 0; i < groupDatas.length; i++) {
			var groupData = groupDatas[i];
			groupHtml += groupHtmlString(groupData);
		}
		$('#group_list').html(groupHtml);
		groupCellOneClick();
		if (groupDatas.length == 0) {  //只有一个集团 隐藏切换
           $('#section1').hide();
           $('#group_list').hide();
		}
	}
	function setupGroupData2(groupDatas){
		var groupHtml = '';
		for (var i = 0; i < groupDatas.length; i++) {
			var groupData = groupDatas[i];
			groupHtml += groupHtmlString2(groupData);
		}
		$('#group_list2').html(groupHtml);
		groupCellTwoClick2();
		if (groupDatas.length == 0) {   //只有一个集团 隐藏切换
           $('#section2').hide();
           $('#group_list2').hide();
		}
	}
	function groupHtmlString(data){
		var isSelected = "";
        var jid = $api.getStorage('cfnetppjxid');
        // var userTypeString = userTypeStr(data.usertpye);
		if (jid == data.id) {
			isSelected = " mui-selected";
		}
		// return '<li id="'+data.id+','+data.usertpye+'" class="group_cell mui-table-view-cell'+isSelected+'">\
		return '<li id="'+data.id+'" class="group_cell mui-table-view-cell'+isSelected+'">\
				<a class="mui-navigate-right base_dark_grey base_content_font">'+
					data.name+
					// '<span class="sub-title">'+userTypeString+'</span>'+
				'</a>\
			</li>';
	}
	function groupHtmlString2(data){
		var isSelected = "";
        var jid = $api.getStorage('cfnetppjid');
        var uType = $api.getStorage('cfnetTrainSelectType');
        var userTypeString = userTypeStr(data.usertpye);
		if (jid == data.id && uType == data.usertpye) {
			isSelected = " mui-selected";
		}
		return '<li id="'+data.id+','+data.usertpye+'" class="group_cell2 mui-table-view-cell'+isSelected+'">\
				<a class="mui-navigate-right base_dark_grey base_content_font">'+
					data.name+
					'<span class="sub-title">'+userTypeString+'</span>'+
				'</a>\
			</li>';
	}
	function userTypeStr(type){
		if (type == 1) {//教师
			return '教师';
		}else if(type == 2){//师傅
			return '师傅';
		}else if(type == 3){//hr
			return 'HR';
		}else{//学生
			return '学生'
		}
	}
	function groupCellOneClick(){
		$('.group_cell').unbind('click');
		$('.group_cell').click(function(){
			var currentJid = $(this).attr('id');
			var name = "";
            for (var i = dataSource.length - 1; i >= 0; i--) {
            	if (dataSource[i].id == currentJid) {
            		name = dataSource[i].name;
            		index = i;
            	}
            }
        	if (currentJid != $api.getStorage('cfnetppjxid')) {
				/*存上选中的xid*/
				$api.setStorage('cfnetppjxid', currentJid);
				$api.setStorage('tempjid', currentJid);//存储临时jid用于解决实习学习集团id问题
				$api.setStorage('cfnetppjxidname', name);
                api.closeWin();
              	$api.setStorage('cfnetSelectType',dataSource[index].usertpye);
            	if(dataSource2.length >= (index+1) && dataSource2[index].usertpye==2){
              		$api.setStorage('cfnetSelectType',1);
              	}
				api.sendEvent({
					name: 'changeJxjidNotifi',
					extra: {
						currentJxjid: currentJid
					}
				});
				api.sendEvent({
					name: 'changeLeftMenuNotifi',
					extra: {
						userType:$api.getStorage('cfnetSelectType'),
						school: name,
					}
				});
	     	}
		});
	}
	function groupCellTwoClick2(){
		$('.group_cell2').unbind('click');
		$('.group_cell2').click(function(){
			var jidAndType = $(this).attr('id');
			var arr = jidAndType.split(',');
			var currentJid = arr[0];
			var currentType = arr[1];
			var name = "";
			var index = 0;
            for (var i = dataSource2.length - 1; i >= 0; i--) {
            	if (dataSource2[i].id == currentJid && dataSource2[i].usertpye == currentType) {
            		name = dataSource2[i].name;
            		index = i;
            	}
            }
            if (!(currentJid == $api.getStorage('cfnetppjid') && currentType == $api.getStorage('cfnetTrainSelectType'))) {
				/*存上选中的jid*/
				$api.setStorage('cfnetppjid', currentJid);
			    $api.setStorage('cfnetppjidname', name);
			    $api.setStorage('cfnetTrainSelectType', currentType);
		        // api.sendEvent({
          //           name: 'changeJidNotifi',
          //           extra: {
          //               jid: currentJid,
          //           }
          //       });
               //  api.closeToWin({
               //      name:'index',
               // });
               api.closeWin();
     	  	}
		});
	}
</script>
</html>
